package com.myfoon.model.entity;


import com.tangosol.io.ExternalizableLite;

import com.tangosol.util.ExternalizableHelper;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.Externalizable;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;

@Entity
@Table(name = "COUNTRY_NAME")
@Cache (usage=CacheConcurrencyStrategy.READ_ONLY)
public class CountryName implements Serializable {    
    private Integer id;    
    private Country country;
    private String language;
    private String name;
    
    public CountryName() {
    }

    public void setId(Integer id) {
        this.id = id;
    }
    
    @Id 
    @GeneratedValue(generator = "CountryNameSequence", strategy = GenerationType.AUTO)
    @SequenceGenerator(name = "CountryNameSequence", allocationSize = 1, sequenceName = "COUNTRY_NAME_SEQ_01")
    @Column(name = "ID", unique = true, nullable = false, precision = 10, scale = 0)
    public Integer getId() {
        return id;
    }

    public void setCountry(Country country) {
        this.country = country;
    }

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "COUNTRY_ID")
    public Country getCountry() {
        return country;
    }

    public void setLanguage(String language) {
        this.language = language;
    }

    @Column(name = "LANGUAGE", length = 5, nullable = false)    
    public String getLanguage() {
        return language;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Column(name = "NAME", length = 50, nullable = false)    
    public String getName() {
        return name;
    }

    public void readExternal(ObjectInput dataInput) throws IOException {
        id = ExternalizableHelper.readInt(dataInput);
        country = (Country)ExternalizableHelper.readObject(dataInput);
        language = ExternalizableHelper.readUTF(dataInput);
        name = ExternalizableHelper.readUTF(dataInput);
        
    }

    public void writeExternal(ObjectOutput dataOutput) throws IOException {
        ExternalizableHelper.writeInt(dataOutput, id);
        ExternalizableHelper.writeObject(dataOutput, country);
        ExternalizableHelper.writeUTF(dataOutput, language);
        ExternalizableHelper.writeUTF(dataOutput, name);
    }
}
